<?php
/* dragon.hu add 2015.6.18 
 * smeltincome
 */

defined('BASEPATH') or die('forbidden');

class Smeltincome_Controller extends Controller
{
	private $inc;
	private $conn;
	private $nameConn;
	private $nameList;
	private $professionList;
	
	function _init()
	{
		$this->inc = $this->config['inc'];
		$this->professionList = $this->inc['type_proffessionid'];
		check_level(50, segment(0), segment(1), segment(2, 'index'));
		set_time_limit(0);
		$areanum = $_SESSION['area_selected_id'];
		if ($areanum == '')
		{
			echo "<script>alert('".translate('C_SELECT_AREA_TEXT')."');</script>";
			return;
		}
		$this->nameConn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		$this->nameConn->query("SELECT id, name FROM player");
		while ($n = $this->nameConn->get_array('default'))
		{
			$this->nameList[$n['id']] = $n['name'];
		}
		$this->nameConn->free_all();
		
		//连接log数据库
		$this->conn = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_LOG);
	}
	
	function index()
	{
		$this->view->display("logmonetary/smeltincome/index");
	}
	
	function flexigrid()
	{
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
		$sql = "SELECT COUNT(*) AS num FROM smelt_income WHERE {$where}";
		$one = $this->conn->one($sql);
		$total = $one['num'];
		
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder}" : "";
		$sql = "SELECT {$colsinfo} FROM smelt_income WHERE {$where} {$orderby} LIMIT {$offset}, {$rp}";
		$this->conn->query($sql);
		while ($n = $this->conn->get_array('default'))
		{
			$n['role_id'] = $this->nameList[$n['role_id']]."(".$n['role_id'].")";
			$n['profession_type'] = $this->professionList[$n['profession_type']]."(".$n['profession_type'].")";
			$rows[] = array('id' => $n['id'], 'cell' => $n);
		}
		
		$result = array('page' => $page, 'total' => $total, 'rows' => $rows);
		$this->conn->free_all();
		echo json_encode($result);
	}
} 

?>